Repository navigation
fix(server): require an auth token for the API server - #690
Officeyutong wants to merge 2 commits into
Conversation
|
Targeted API Server authentication regression tests passed against ckb-cli PR #690 commit Coverage includes startup token validation; unauthenticated or invalid-token requests with Origin headers, in batches, and over persistent connections; authentication for read-only requests and servers without a private key; successful authenticated balance queries; unauthenticated CORS preflight; and valid transfers after a rejected request. Could you update the authentication-related parts of
I also found two non-blocking, pre-existing documentation mismatches that can be handled separately:
针对 ckb-cli PR #690 提交 用例覆盖启动时的 token 校验;缺失或错误 token 的请求(包括不同的 Origin、批量请求和长连接);只读查询和未配置私钥的服务也需认证;认证后的余额查询、无需认证的跨域预检,以及请求被拒绝后继续正常转账。 能否在这次 PR 中更新
另外还发现两处非阻塞的旧文档问题,可以后续处理:
|
|
i also check this |
What problem does this PR solve?
ckb-cli server --privkey-pathexposes atransfermethod that signs and sends a transfer to a caller-chosen address and amount, with no password or confirmation. The server has no authentication, and its CORS setting allows any origin. Listening only on 127.0.0.1 doesn't help, because a browser on the same machine can reach that address.So any website opened while the server is running can call
transferwithfetch()and drain the wallet.What is changed and how it works?
--auth-token <token>option, and the server doesn't start without it. A request must carry the headerAuthorization: Bearer <token>, otherwise it gets401 Unauthorizedand no method is run. A website doesn't know the token, so this covers requests from any origin, includingOrigin: nulland DNS rebinding.OPTIONSrequests don't need the token, because browsers don't send custom headers on CORS preflight and these requests don't run any method. This keeps browser clients that have the token working.docs/API-Server.md.Check List
Tests
src/subcommands/api_server.rs, which send raw HTTP requests to a real server:OPTIONSrequests don't run any method;--auth-tokenis a command line error.--auth-tokenfails; without a valid tokenPOSTgets 401, and with the token it reaches the RPC handler.cargo clippy --all-targetswith theCLIPPY_OPTSfrom the Makefile passes.Side effects
ckb-cli serversetup must add--auth-token, and its clients must send the header. This includes setups without--privkey-path.Release note